﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.Messaging;

namespace IdentityNotes.Examples.CustomActivityLibrary
{
	public partial class SendSpeechServerMessageActivity: Activity
	{
		public SendSpeechServerMessageActivity()
		{
			InitializeComponent();
		}

        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [Category("Properties")]
        public string Message
        {
            get { return (string)this.GetValue(SendSpeechServerMessageActivity.MessageProperty); }
            set { this.SetValue(SendSpeechServerMessageActivity.MessageProperty, value); }
        }

        public static DependencyProperty MessageProperty = DependencyProperty.Register("Message", typeof(string), typeof(SendSpeechServerMessageActivity));

        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [Category("Properties")]
        public string Queue
        {
            get { return (string)this.GetValue(SendSpeechServerMessageActivity.QueueProperty); }
            set { this.SetValue(SendSpeechServerMessageActivity.QueueProperty, value); }
        }

        public static DependencyProperty QueueProperty = DependencyProperty.Register("Queue", typeof(string), typeof(SendSpeechServerMessageActivity));



        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            MessageQueue queue = new MessageQueue(this.Queue);
            Message message = new Message(this.Message);
            MessageQueueTransaction transaction = new MessageQueueTransaction();

            transaction.Begin();
            queue.Send(message, transaction);
            transaction.Commit();

            return base.Execute(executionContext);
        }


	}
}
